<?php
class Sys_media_area_model extends CI_Model {

	public function __construct(){
		parent::__construct();
		$this->db = $this->load->database('default',true);
	}

	public function  query_media_areas() {
		$sql ="select * from sys_media_area where  be_delete ='0' and  parent_id ='$parent_id' order by media_area_id asc";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->result_array();
		}
	}

	public function query_media_area_info($media_area_id){
		$sql ="select * from  sys_media_area where  be_delete ='0' and  media_area_id ='$media_area_id' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}

	public function query_media_area_info_by_name($media_area_name){
		$sql ="select * from  sys_media_area where be_delete ='0' and  media_area_name ='$media_area_name' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}
	public function insert_media_area($media_area){
		$media_area['be_delete']=0;
		$this->db->insert('sys_media_area',$media_area);
	}
	public function update_media_area($media_area,$media_area_id){
		$this->db->where('media_area_id',$media_area_id);
		$this->db->update('sys_media_area',$media_area);
	}

	public function set_delete_media_area($media_area_id){
		$sql ="update sys_media_area set be_delete ='1' where media_area_id='$media_area_id'";
		$this->db->query($sql);
	}

	public function query_media_area_list($start,$limit) {
		$sql ="select media_area_id,media_area_name from sys_media_area where be_delete ='0'  order by media_area_id asc limit $start,$limit";
		$query =$this->db->query($sql);
		if ($query) {
			return $query->result_array();
		}
	}

	public function query_media_area_num(){
		$sql ="select count(media_area_id) as num from sys_media_area  where be_delete ='0' ";
		$query =$this->db->query($sql);
		if ($query){
			$row =$query->row_array();
			return $row['num'];
		}
	}
	public function get_all_media_area() {
		$sql ="select media_area_id,media_area_name from sys_media_area where be_delete ='0'  order by media_area_id asc";
		$query =$this->db->query($sql);
		if ($query) {
			return $query->result_array();
		}
	}
}
?>